<?php
/**
 * 幻灯图修改管理页面
 * author:wang
 * mail:970633164@qq.com
 */
define("PHP_IN", true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$adid = isset($_GET['adid']) ? $_GET['adid'] : 0;
$page = isset($_GET['page']) ? $_GET['page'] : 1;

$sql = "SELECT * FROM slidead WHERE adid = $adid";
$result = $db->query($sql);
$slide = $db->fetch_one($result);

if (isset($_POST['dosubmit'])) {
    $adid = $_POST['adid'];
    $name = $_POST['name'];
    $url = $_POST['url'];
    $isdisplay = $_POST['isdisplay'];
    $t = time();
    $srcname = $_POST['src'];
    if (isset($_FILES)) {
        if ($_FILES['photo']['error'] == 0) {
            unlink($slide_src_up . $srcname);
            $filename = file_ext($_FILES['photo']['name']);
            $srcname = $t . rand(1, 10000) . $filename;
            $path = $slide_src_up . $srcname;
            $upload = move_uploaded_file($_FILES['photo']['tmp_name'], $path);
        }
    }

    $sql = "UPDATE slidead SET name='$name',src='$srcname',url='$url',
          isdisplay='$isdisplay' WHERE adid = $adid";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "slide_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}

$smarty->assign("slide",$slide);
$smarty->assign("page",$page);

$smarty->display("slide_edit.tpl");
$db->close();
?>
